package com.demo.datastructure.reorder.insertionSort;

/**
 * @description: 插入排序
 * @author: ljr
 * @time: 2021/5/2 16:32
 */
public class MyInsertionSort3 {


    // 插入排序，a表示数组，n表示数组大小
    public static void insertionSort(int[] args, int n) {
         for(int i = 1; i < n; i++){
             int val = args[i];
             int j = i-1;
             for(; j >= 0; j--){
                 if(args[j] > val){
                     args[j+1] = args[j];
                 }else{
                     break;
                 }
             }
             args[j+1] = val;
         }
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3,3,2,5,1,6};
        MyInsertionSort3.insertionSort(nums,6);
        for(int num : nums){
            System.out.println(num);
        }
    }

}
